﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam4.Entity;
using MockPrjTeam4.Biz;
using MockPrjTeam4.Common;

namespace MockPrjTeam4.Pages.Forms
{
    public partial class SupportingMaterialEdit : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = Methods.ConvertNumber(Request.QueryString["ID"]);
            SupportingMaterial sm = SupportingMaterialBiz.GetSupportingMaterialById(id);
            if (!IsPostBack)
            {
                txtURL.Text = sm.Url;
                txtDes.Text = sm.Description;
                txtType.Text = sm.Type;
                txtAddedDate.Text = sm.AddedDate.ToString();
                User us = UserBiz.GetUserById(sm.UserId);
                ddlAddedBy.DataSource = UserBiz.GetUser();
                ddlAddedBy.DataBind();
                ddlAddedBy.Text = us.Account;
            }
        }

        protected void btnSaveSupporting_Click(object sender, EventArgs e)
        {
            int id = Methods.ConvertNumber(Request.QueryString["ID"]);
            SupportingMaterial sm = SupportingMaterialBiz.GetSupportingMaterialById(id);
            sm.Url = txtURL.Text;
            sm.Description = txtDes.Text;
            sm.IsActive = true;
            sm.Type = txtType.Text;
            sm.UserId = Methods.ConvertNumber(ddlAddedBy.SelectedValue);
            sm.OrganisationId = id;
            SupportingMaterialBiz.EditSupportingMaterial(sm);
            lblMessage.Text = "You editted " + "<span style='color:blue'>" +
                sm.Url + "</span>" + " successfully";
        }

        protected void btnBackSupporting_Click(object sender, EventArgs e)
        {
            int id = Methods.ConvertNumber(Request.QueryString["OrgID"]);
            Response.Redirect(string.Format("EditOrganisation.aspx?ID={0}", id));
        }
    }
}